'use strict';

/**
 * @param {Egg.Application} app - egg application
 */

const routes = [
    // index
    {
        path: '/',
        module: 'index',
        name: 'index'
    },
    {
        // 自动部署项目
        path: '/deploy',
        module: 'index',
        name: 'deploy'
    },

    // 用户
    {
        path: '/user/register',
        module: 'user',
        name: 'add'
    },
    // 登录
    {
        path: '/user/login',
        module: 'user',
        name: 'login'
    },
    // 登录
    {
        path: '/user/getUserInfo',
        module: 'user',
        name: 'getUserInfo'
    },
    // 登出
    {
        path: '/user/logout',
        module: 'user',
        name: 'logout'
    },
    // 获取验证码
    {
        path: '/user/getSmsCode',
        module: 'user',
        name: 'getSmsCode'
    },

    // 食品相关api
    {
        path: '/food/addFoodCategory',
        module: 'food',
        name: 'addFoodCategory'
    },
    {
        path: '/food/addFoods',
        module: 'food',
        name: 'addFoods'
    },
    {
        path: '/food/foodList',
        module: 'food',
        name: 'foodList'
    },
    {
        path: '/food/findFoods',
        module: 'food',
        name: 'findFoods'
    },
    {
        path: '/food/findAllFoods',
        module: 'food',
        name: 'findAllFoods'
    },

    // 订单相关api
    {
        path: '/order/createOrder',
        module: 'order',
        name: 'createOrder'
    },
    {
        path: '/order/delOrder',
        module: 'order',
        name: 'delOrder'
    }, 
    {
        path: '/order/orderList',
        module: 'order',
        name: 'orderList'
    },

    // 购物车
    {
        path: '/cart/index',
        module: 'cart',
        name: 'index'
    }, {
        path: '/cart/addCart',
        module: 'cart',
        name: 'addCart'
    }, {
        path: '/cart/cartList',
        module: 'cart',
        name: 'cartList'
    }, {
        path: '/cart/delCart',
        module: 'cart',
        name: 'delCart'
    }
    , {
        path: '/cart/clearCart',
        module: 'cart',
        name: 'clearCart'
    }
]



module.exports = app => {
    // 旧接口
    const {
        router,
        controller
    } = app;
    routes.forEach(item => {
        router.get(item.path, controller[item.module][item.name]);
        router.post(item.path, controller[item.module][item.name]);
    })
};
